\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[margin=2cm]{geometry}
\usepackage{booktabs}
\usepackage[capposition=top]{floatrow}
\usepackage{bm}
\usepackage{graphicx}
\usepackage[affil-it]{authblk}
\usepackage{natbib}
\usepackage{setspace}
\usepackage[bottom]{footmisc}
\usepackage{lscape}
\usepackage{threeparttable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage{csquotes}
\usepackage{tikzsymbols}
\usepackage{textcomp}




\begin{document}

\title{Replication Code for:\\A Little Lift in the Iron Curtain: Emigration Restrictions and Criminal Activity in Socialist East Germany}
\date{\today}
\author{Hans Lueders}


\maketitle

<<include=F>>=
### packages
library(ggplot2)
library(foreign)
library(stargazer)
library(xtable)
library(maptools)
library(gridExtra)
library(ggmap)
library(rgdal)
library(sp)
library(lfe)
library(dplyr)
library(sf)
library(readxl)
library(ggpubr)

### set working directory
# adjust here
path <- ""
setwd(path)
@

\section*{Load and prepare data}

\textit{Notes:} The replication files contain three datasets:
\begin{enumerate}
\item ``county-level data'' is a panel data set with all relevant variables used in analyses at the county-year-level. See below for details.
\item ``crime-level data'' contains detailed information about individual crimes committed in the former GDR. This data was compiled from original files obtained from the German Federal Archives. It is used to create descriptive statistics and in the analysis of crime damage.
\item ``additional data'' contains annual information on the volume of exit visa applications, international migration to and from the former GDR, and government expenditures. This data is used to create several descriptive statistics in the main text and the appendix.
\end{enumerate}

<<include=F>>=
### load and prepare data files 1: county-level data
# load data
d <- read.dta(paste(path, "/data/ALittleLiftInTheIronCurtain_countydata.dta", sep=""))

# increase in emigration as treatment
d$emiInt_diff <- d$emiInt1984 - d$emiInt1979
d$emiInt_diff_dich <- ifelse(d$emiInt_diff <= median(d$emiInt_diff[d$year==1984], na.rm=T), 0,
                             ifelse(d$emiInt_diff > median(d$emiInt_diff[d$year==1984], na.rm=T), 1, NA))

# code post-treatment indicators 1a: 1983 is baseline
d$post84 <- 0
d$post84[d$year >= 1984] <- 1

# code post-treatment indicators 1b: 1984 is baseline
d$post85 <- 0
d$post85[d$year >= 1985] <- 1

# code post-treatment indicators 2a: years before/after treatment onset (for event study of crime data)
d$yearEVENT85 <- NA
d$yearEVENT85[d$year <= 1990] <- d$year[d$year <= 1990] - 1984
d$yearEVENT85 <- factor(d$yearEVENT85, levels=c(-8,-4,-3,0,1,2,3,4,5,6), 
                      labels = c("1976", "1980","1981", "1984", 
                                 "1985", "1986", "1987", "1988", "1989", "1990"))
d$yearEVENT85 <- relevel(d$yearEVENT85, ref = "1984")

# code post-treatment indicators 2b: years before/after treatment onset (for event study of petitions data)
d$yearEVENT85_demand <- NULL
d$yearEVENT85_demand[d$year>=1976 & d$year <= 1989] <- d$year[d$year>=1976 & d$year <= 1989] - 1984
d$yearEVENT85_demand <- factor(d$yearEVENT85_demand, levels=seq(-8,5), 
                      labels = c("1976", "1977", "1978", "1979", "1980",
                                 "1981", "1982", "1983", "1984", "1985",
                                 "1986", "1987", "1988", "1989"))
d$yearEVENT85_demand <- relevel(d$yearEVENT85_demand, ref = "1984")

# code post-treatment indicators 3: years after treatment onset
d$yearPOST <- ifelse(d$year<=1984, 0, NA)
d$yearPOST[d$year==1985] <- 1
d$yearPOST[d$year==1986] <- 2
d$yearPOST[d$year==1987] <- 3
d$yearPOST[d$year==1988] <- 4
d$yearPOST[d$year==1989] <- 5
d$yearPOST <- factor(d$yearPOST, levels=0:5,
                     labels = c("t=0", "t+1 (1985)", "t+2 (1986)", "t+3 (1987)", "t+4 (1988)", "t+5 (1989)"))




### load and prepare data files 2: crime-level data
# load data
crimes <- read.dta(paste(path, "/data/ALittleLiftInTheIronCurtain_crimedata.dta", sep=""))

# code post-treatment indicators -- 1984 is baseline
crimes$post85 <- 0
crimes$post85[crimes$year >= 1985] <- 1

# code age groups
crimes$agegroup <- NA
crimes$agegroup[crimes$age <= 15] <- 1
crimes$agegroup[crimes$age >= 16 & crimes$age <= 18] <- 2
crimes$agegroup[crimes$age >= 19 & crimes$age <= 24] <- 3
crimes$agegroup[crimes$age >= 25 & crimes$age <= 29] <- 4
crimes$agegroup[crimes$age >= 30 & crimes$age <= 39] <- 5
crimes$agegroup[crimes$age >= 40 & crimes$age <= 49] <- 6
crimes$agegroup[crimes$age >= 50 & crimes$age <= 64] <- 7
crimes$agegroup[crimes$age >= 65] <- 8
crimes$agegroup <- factor(crimes$agegroup, levels=1:8,
                     labels = c("-15", "16-18", "19-24", "25-29", "30-39", "40-49", "50-64", "65+"))









### load and prepare data files 3: additional data
# international migration
migdata <- read_xlsx(paste(path, "/data/A Little Lift in the Iron Curtain - additional data.xlsx", sep=""), sheet="International migration")

# destination counties
destcountries <- read_xlsx(paste(path, "/data/A Little Lift in the Iron Curtain - additional data.xlsx", sep=""), sheet="Destination countries")

# demographics of emigrants
demo <- read_xlsx(paste(path, "/data/A Little Lift in the Iron Curtain - additional data.xlsx", sep=""), sheet="Demographics")

# government expenditures
govexp <- read_xlsx(paste(path, "/data/A Little Lift in the Iron Curtain - additional data.xlsx", sep=""), sheet="Gov't expenditures")

# successful exits
exits <- read_xlsx(paste(path, "/data/A Little Lift in the Iron Curtain - additional data.xlsx", sep=""), sheet="Successful exits")
@



\clearpage

\section*{Main text}

\subsection*{Figure 1: Consequences of the 1983 emigration reform}

<<results='asis', echo=F, fig.width=7, fig.height=4, warning=F>>=
### plot
p <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +
  
  annotate("text", x=1970, y=35000, label = "Emigration", size=5) +
  annotate("text", x=1975, y=10000, label = "Exit visa\napplications", size=5) +
  
  geom_line(data=migdata[migdata$year<=1988,], aes(x=year, y=applications, col="1"),size=1.5) + 

  geom_line(data=migdata[!is.na(migdata$emi) & migdata$year<=1988,], aes(x=year, y=emi, col="2"),size=1.5) +
  
  scale_color_manual(values = c("gray70", "gray10"), labels = c("Exit visa applications", "Emigration"), name="") +
  
  scale_x_continuous(breaks=seq(1964,1988,2)) +
  scale_y_continuous(limits=c(0,80000), breaks=seq(0,80000,20000),
                     labels=c("0","20,000", "40,000", "60,000", "80,000")) +
  theme_bw() + 
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_blank(),
        axis.text = element_text(size=12),
        legend.position = "none",
        legend.text = element_text(size=12))
p
ggsave("Figure1_ExitEmi6588.png", p, width=7,height=4)
@

\clearpage

\subsection*{Figure 2: Crimes by category}

<<results='asis', echo=F, warning=F, fig.width=8, fig.height=5>>=
### create some summary statistics
# share of norms by type
out <- as.data.frame(table(crimes$normCLASSdet))
colnames(out) <- c("normDE", "freq")
out$share <- prop.table(table(crimes$normCLASSdet))*100
out$normEN <- c("State sovereignty (16)", "Person, life, health (4)", "Freedom and dignitiy (8)",
                "Youth and family (10)", "State property (1)", "National economy (15)",
                "Personal and private property (2)", "General security (3)", 
                "Resistance to state measures (12)", "Illegal border crossing (7)", 
                "Rowdyism (9)", "Interference with state activities (13)",
                "State slander (11)", "Administration of justice (6)", 
                "Asocial behavior (5)", "Misc. (14)")


# normclass
out$normCLASS <- c(2,1,1,1,1,1,1,1,2,3,2,2,2,1,2,1)
out$normCLASS <- factor(out$normCLASS, levels = 1:3,
                        labels = c("ordinary", "political", "border-related crimes"))

### Plot
p <- ggplot() + 
  geom_bar(data=out, aes(x=reorder(normEN,share), y=share, fill=normCLASS),
           stat="identity") +
  scale_fill_manual(values = c("seashell3", "seashell4", "gray20"), name="") +
  scale_y_continuous(limits=c(0,25), breaks=seq(0,25,5)) +
  ylab("Share (%)") +
  coord_flip()  +
  theme_bw() +
  theme(plot.title = element_text(size=14, face="bold", hjust=.5),
        axis.title.x = element_text(size=14, face="bold"),
        axis.title.y = element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank(),
        legend.text = element_text(size=12),
        strip.text = element_text(size=14, face="bold"))  
p
ggsave("Figure2_CrimeDistribution.png", p, width=8, height=5)
@

\clearpage

\subsection*{Figure 3: Crimes by year}

<<results='asis', echo=F, fig.width=7, fig.height=5, warning=F>>=
### data preparation
# aggregation
agg <- aggregate(d[,c("persons_total_all", 
                      "persons_total_ordinary",
                      "persons_total_antiregime",
                      "persons_total_antiregimeNoBorder",
                      "persons_total_border")],
                 by=list("year"=d$year), FUN=sum, na.rm=T)
agg <- subset(agg, year %in% c(1976,1980,1981,1984,1985,1987,1988,1989))


# reshape long
agg.long <- data.frame(matrix(nrow=dim(agg)[1]*5,ncol=2))
colnames(agg.long) <- c("year", "norm")
agg.long$year <- rep(c(1976,1980,1981,1984,1985,1987,1988,1989),5)
agg.long$norm <- rep(1:5, each=8)
agg.long$norm <- factor(agg.long$norm, levels=1:5,
                        labels = c("All crimes",
                                   "Ordinary crimes",
                                   "Political crimes",
                                   "Political crimes (excl. border)",
                                   "Border-related crimes"))
agg.long$persons_total <- c(agg$persons_total_all, agg$persons_total_ordinary, agg$persons_total_antiregime, agg$persons_total_antiregimeNoBorder, agg$persons_total_border)

### Plots
p1 <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.65) +  
  geom_point(data=agg.long[agg.long$norm == "All crimes",], aes(x=year, y=persons_total), size=2.5) + 
  geom_line(data=agg.long[agg.long$norm == "All crimes",], aes(x=year, y=persons_total), size=1) + 
  scale_x_continuous(limits = c(1976,1990), breaks = seq(1976,1990,2)) +
  scale_y_continuous(limits = c(140000,170000), breaks = seq(140000,170000,5000),
                     labels = c("140,000", "145,000", "150,000", "155,000", "160,000", "165,000", "170,000")) +    
  facet_wrap(~norm, scales="free_y") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title =  element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank()) 
p2 <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.65) +  
  geom_point(data=agg.long[agg.long$norm == "Ordinary crimes",], aes(x=year, y=persons_total), size=2.5) + 
  geom_line(data=agg.long[agg.long$norm == "Ordinary crimes",], aes(x=year, y=persons_total), size=1) + 
  scale_x_continuous(limits = c(1976,1990), breaks = seq(1976,1990,2)) +
  scale_y_continuous(limits = c(90000,140000), breaks=seq(90000,140000,10000),
                     labels = c("90,000", "100,000", "110,000", "120,000", "130,000", "140,000")) +    
  facet_wrap(~norm, scales="free_y") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title =  element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank()) 

p3 <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.65) +  
  geom_point(data=agg.long[agg.long$norm == "Political crimes",], aes(x=year, y=persons_total), size=2.5) + 
  geom_line(data=agg.long[agg.long$norm == "Political crimes",], aes(x=year, y=persons_total), size=1) + 
  scale_x_continuous(limits = c(1976,1990), breaks = seq(1976,1990,2)) +
  scale_y_continuous(limits = c(20000,50000), breaks=seq(20000,50000,5000),
                     labels = c("20,000", "25,000", "30,000", "35,000", "40,000", "45,000", "50,000")) +  
  facet_wrap(~norm, scales="free_y") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title =  element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank()) 

p4 <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.65) +  
  geom_point(data=agg.long[agg.long$norm == "Political crimes (excl. border)",], aes(x=year, y=persons_total), size=2.5) + 
  geom_line(data=agg.long[agg.long$norm == "Political crimes (excl. border)",], aes(x=year, y=persons_total), size=1) + 
  scale_x_continuous(limits = c(1976,1990), breaks = seq(1976,1990,2)) +
  scale_y_continuous(limits = c(16000,28000), breaks=seq(16000,28000,2000),
                     labels = c("16,000", "18,000", "20,000", "22,000", "24,000", "26,000", "28,000")) +  
  facet_wrap(~norm, scales="free_y") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title =  element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank()) 
p5 <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.65) +  
  geom_point(data=agg.long[agg.long$norm == "Border-related crimes",], aes(x=year, y=persons_total), size=2.5) + 
  geom_line(data=agg.long[agg.long$norm == "Border-related crimes",], aes(x=year, y=persons_total), size=1) + 
  scale_x_continuous(limits = c(1976,1990), breaks = seq(1976,1990,2)) +
  scale_y_continuous(limits = c(0,30000), breaks=seq(0,30000,5000),
                     labels = c("0", "5,000", "10,000", "15,000", "20,000", "25,000", "30,000")) +
  facet_wrap(~norm, scales="free_y") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title =  element_blank(),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank()) 


blank <- ggplot() + theme_void()

p <- ggarrange(
    ggarrange(blank, p1, blank, nrow = 1,
        widths = c(0.25,1,0.25), legend = "none"),
    ggarrange(p2,p3, nrow = 1,
        widths = c(1,1), legend = "none"),    
    ggarrange(p4,p5, nrow = 1,
        widths = c(1,1), legend = "none"),
    nrow = 3,
    legend = "none"
)
p
ggsave("Figure3_CrimeYear.png",p,width=9, height=9)
@

\clearpage

\subsection*{Table 2: Change in crime incidence after the emigration wave}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m5 <- felm(persons_total_border ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)

### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Figure 4: Event study plot}

<<results='asis', echo=F, warning=F, fig.width=12, fig.height=4>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * yearEVENT85 | county + year | 0 | county, data=d)
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * yearEVENT85 | county + year | 0 | county, data=d)
m3 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * yearEVENT85 | county + year | 0 | county, data=d)
m4 <- felm(persons_total_border ~ emiInt1984_dich * yearEVENT85 | county + year | 0 | county, data=d)

### extract coefficients
# create empty output container
out <- data.frame(matrix(nrow=56, ncol=4))
colnames(out) <- c("year", "outcome", "b", "se")
out$year <- rep(1976:1989, 4)
out$outcome <- rep(1:4, each=14)
out$outcome <- factor(out$outcome, levels=1:4,
                      labels = c("all crimes",
                                 "ordinary crimes",
                                 "political crimes (excl. border)",
                                 "border-related crimes"))
out[out$year == 1984, c("b", "se")] <- 0

# get coefficients
out[out$year == 1976 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[9,1:2]
out[out$year == 1980 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[10,1:2]
out[out$year == 1981 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[11,1:2]
out[out$year == 1985 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[12,1:2]
out[out$year == 1987 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[13,1:2]
out[out$year == 1988 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[14,1:2]
out[out$year == 1989 & out$outcome == "all crimes",c("b", "se")] <- summary(m1)$coef[15,1:2]

out[out$year == 1976 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[9,1:2]
out[out$year == 1980 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[10,1:2]
out[out$year == 1981 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[11,1:2]
out[out$year == 1985 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[12,1:2]
out[out$year == 1987 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[13,1:2]
out[out$year == 1988 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[14,1:2]
out[out$year == 1989 & out$outcome == "ordinary crimes",c("b", "se")] <- summary(m2)$coef[15,1:2]

out[out$year == 1976 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[9,1:2]
out[out$year == 1980 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[10,1:2]
out[out$year == 1981 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[11,1:2]
out[out$year == 1985 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[12,1:2]
out[out$year == 1987 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[13,1:2]
out[out$year == 1988 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[14,1:2]
out[out$year == 1989 & out$outcome == "political crimes (excl. border)",c("b", "se")] <- summary(m3)$coef[15,1:2]

out[out$year == 1976 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[9,1:2]
out[out$year == 1980 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[10,1:2]
out[out$year == 1981 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[11,1:2]
out[out$year == 1985 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[12,1:2]
out[out$year == 1987 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[13,1:2]
out[out$year == 1988 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[14,1:2]
out[out$year == 1989 & out$outcome == "border-related crimes",c("b", "se")] <- summary(m4)$coef[15,1:2]


### Plot
p <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=Inf, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +  
  geom_hline(yintercept = 0, lty=2) +
  geom_point(data=out[out$outcome != "all crimes",], aes(x=year, y=b), size=2.6) +
  geom_errorbar(data=out[out$outcome != "all crimes",], aes(x=year, ymin=b-1.96*se, ymax=b+1.96*se),
                width=0, size=1) +
  facet_wrap(~outcome, scale="free_y") +
  scale_x_continuous(limits = c(1975.5, 1989.75),
                     breaks = seq(1976,1990,2)) +
    theme_bw() +
    theme(strip.text = element_text(size=14, face="bold", hjust=.5),
          axis.title = element_blank(),
          axis.text = element_text(size=12),
          legend.position = "bottom",
          legend.title = element_blank(),
          legend.text = element_text(size=12))  
p
ggsave("Figure4_CrimeEventStudy_persons.png", p, width=12, height=4)
@

\clearpage

\subsection*{Table 3: Short- vs. long-term consequences}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_ordinary ~ emiInt1984_dich * as.factor(yearPOST) | county + year | 0 | county, data=d)
m2 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * as.factor(yearPOST) | county + year | 0 | county, data=d)
m3 <- felm(persons_total_border ~ emiInt1984_dich * as.factor(yearPOST) | county + year | 0 | county, data=d)


### Stargazer output
stargazer(m1,m2,m3,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T, 
          dep.var.labels = c("ordinary","political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "t+1 (1985)",
                             "t+3 (1987)",
                             "t+4 (1988)",
                             "t+5 (1989)",
                             "High emigration (1984) X t+1 (1985)",
                             "High emigration (1984) X t+3 (1987)",
                             "High emigration (1984) X t+4 (1988)",
                             "High emigration (1984) X t+5 (1989)"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table 4: Change in average damage caused after the emigration wave}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(damage_log ~ emiInt1984_dich*post85 + female + SED + as.factor(agegroup) + persons_total | 
             norm + countyID + year | 0 | countyID, data=crimes)
m2 <- felm(damage_log ~ emiInt1984_dich*post85 + female + SED + as.factor(agegroup) + persons_total | 
             norm + countyID + year | 0 | countyID, data=crimes, subset=crimes$damage < quantile(crimes$damage, probs=0.95, na.rm=T))
m3 <- felm(I(damage>0) ~ emiInt1984_dich*post85 + female + SED + as.factor(agegroup) + persons_total | 
             norm + countyID + year | 0 | countyID, data=crimes)
m4 <- felm(I(damage>0) ~ emiInt1984_dich*post85 + female + SED + as.factor(agegroup) + persons_total | 
             norm + countyID + year | 0 | countyID, data=crimes, subset=crimes$damage < quantile(crimes$damage, probs=0.95, na.rm=T))

### Stargazer output
stargazer(m1,m2,m3,m4,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("Damage (log GDR Mark)", "I(Any damage)"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "Female",
                             "SED Party member",
                             "Age group: 16-18",
                             "Age group: 19-24",
                             "Age group: 25-29",
                             "Age group: 30-39",
                             "Age group: 40-49",
                             "Age group: 50-64",
                             "Age group: 65+",
                             "Number of persons involved",
                             "High emigration (1984) X Post-1984"), 
          
          add.lines = list(
            c("Sample", "full", "95 percent", "full", "95 percent"),
            c("Crime-FE?", "YES", "YES", "YES", "YES"),
            c("County-FE?", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table 5: Increase in demand for future emigration following the emigration wave}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt1984_dich*post84
           |countyID + year |0|countyID, 
           data=d)
m2 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt1984_dich*post84
           |countyID + year |0|countyID, 
           data=d)


### Output
stargazer(m1,m2,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("Exit visas", "Domestic affairs (incl. travel)"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) x Post-1984"), 
          add.lines = list(
            c("County-FE?", rep("YES", 2)),
            c("Year-FE?", rep("YES", 2))), 
          digits = 3) 
@


\clearpage

\section*{Appendix}

\subsection*{Table A4: Summary statistics for the analysis of crime data}

<<results='asis', echo=F, warning=F>>=
### compute means and sds
# prepare output matrix
out <- matrix(nrow=18, ncol=5)
colnames(out) <- c("Mean", "SD", "Min", "Median", "Max")

# write a quick function
descfun <- function(dv){
  d$dv <- d[,dv]
  return(c(mean(d$dv, na.rm=T), sd(d$dv, na.rm=T), 
              min(d$dv, na.rm=T), median(d$dv, na.rm=T), max(d$dv, na.rm=T)))
}



# means
out[1,] <- descfun(dv = "emiInt1984")
out[2,] <- descfun(dv = "crimeCount_all")
out[3,] <- descfun(dv = "crimeCount_ordinary")
out[4,] <- descfun(dv = "crimeCount_antiregime")
out[5,] <- descfun(dv = "crimeCount_antiregimeNoBorder")
out[6,] <- descfun(dv = "crimeCount_border")
out[7,] <- descfun(dv = "persons_total_all")
out[8,] <- descfun(dv = "persons_total_ordinary")
out[9,] <- descfun(dv = "persons_total_antiregime")
out[10,] <- descfun(dv = "persons_total_antiregimeNoBorder")
out[11,] <- descfun(dv = "persons_total_border")
out[12,] <- descfun(dv = "citycounty")
out[13,] <- descfun(dv = "university")
out[14,] <- descfun(dv = "tv1")
out[15,] <- descfun(dv = "bordercounty")
out[16,] <- descfun(dv = "SEDshare1946")
out[17,] <- descfun(dv = "popYoung_share1984")
out[18,] <- descfun(dv = "infmort_3yrs")

# rownames
rownames(out) <- c("Emigration rate (1984)", 
                   "all crimes", "ordinary crimes", "political crimes", "political crimes (excl. border)", "border-related crimes",
                   "all crimes (persons)", "ordinary crimes (persons)", "political crimes (persons)", "political crimes (excl. border) (persons)", "border-related crimes (persons)",
                   "Urban county", "College or university", "WGTV access", "Border county", 
                   "SED share (1946)", "Share young population (1984)", "Infant mortality rate")
                  
# print 
print(xtable(out, digits=3, caption="Summary statistics"), caption.placement = "top")
@

\clearpage

\subsection*{Table A5: Demographics by crime type}

<<results='asis', echo=F, warning=F>>=
### create some summary statistics
# share of norms by type
out <- as.data.frame(table(crimes$normCLASSdet))
colnames(out) <- c("normDE", "freq")
out$share <- prop.table(table(crimes$normCLASSdet))*100
out$normEN <- c("State sovereignty (16)", "Person, life, health (4)", "Freedom and dignitiy (8)",
                "Youth and family (10)", "State property (1)", "National economy (15)",
                "Personal and private property (2)", "General security (3)", 
                "Resistance to state measures (12)", "Illegal border crossing (7)", 
                "Rowdyism (9)", "Interference with state activities (13)",
                "State slander (11)", "Administration of justice (6)", 
                "Asocial behavior (5)", "Misc. (14)")


# normclass
out$normCLASS <- c(2,1,1,1,1,1,1,1,2,3,2,2,2,1,2,1)
out$normCLASS <- factor(out$normCLASS, levels = 1:3,
                        labels = c("ordinary", "political", "border-related crimes"))

# demographics
crimes$empstat_worker <- ifelse(crimes$empstat %in% c("Produktionsarbeiter", "Sonstiger Arbeiter"), 1, 0)
crimes$empstat_employee <- ifelse(crimes$empstat %in% c("Angestellter"), 1, 0)
crimes$empstat_unemployed <- ifelse(crimes$empstat %in% c("nicht berufstaetig"), 1, 0)
out$female <- NA
out$age <- NA
out$SED <- NA
out$worker <- NA
out$employee <- NA
out$unemployed <- NA
crimes$count <- 1
for(i in 1:length(out$normDE)){
  out$female[i] <- mean(crimes$female[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
  out$age[i] <- mean(crimes$age[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
  out$SED[i] <- mean(crimes$SED[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
  out$worker[i] <- mean(crimes$empstat_worker[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
  out$employee[i] <- mean(crimes$empstat_employee[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
  out$unemployed[i] <- mean(crimes$empstat_unemployed[crimes$normCLASSdet == out$normDE[i]], na.rm=T)
}


# Table output
out2 <- out
out2$normEN <- NULL
out2$normCLASS <- NULL

out3 <- out2[order(out2$freq, decreasing=T),]

print(xtable(out3, caption = "Demographics by crime type", align = "llcccccccc"),
      include.rownames = FALSE, caption.placement = "top")
@

\clearpage

\subsection*{Figure A1: County-level distribution of key variables}

<<results='asis', echo=F, warning=F>>=
### Prepare shapefiles
# country
shp.country <- st_read(paste(path, "/data/shapefiles/VG-Hist_1989-12-31_STA.shp", sep=""))
shp.country.sub <- subset(shp.country, shp.country$GEN == "Deutsche Demokratische Republik")

# district
shp.district <- st_read(paste(path, "/data/shapefiles/VG-Hist_1989-12-31_LAN.shp", sep=""))
shp.district.sub <- subset(shp.district, shp.district$STG == "DDR")

# county
shp.county <- st_read(paste(path, "/data/shapefiles/VG-Hist_1989-12-31_KRS.shp", sep=""))
shp.county.sub <- subset(shp.county, shp.county$STG == "DDR")


### equalize CRS for all shapefiles
st_crs(shp.county.sub) <- st_crs(shp.district.sub)
st_crs(shp.country.sub) <- st_crs(shp.district.sub)


### aggregate data
agg <- aggregate(d[,c("emiInt1984", "emiInt1984_dich", "pop_total",
                      "persons_total_all", "persons_total_ordinary", "persons_total_antiregime", "persons_total_antiregimeNoBorder", "persons_total_border")],
                 by=list("county"=d$countyID), FUN=mean, na.rm=T)
agg <- subset(agg, county != "")


### merge to shapefile
shp.county.sub$AGS <- shp.county.sub$SDV_AGS
shp.county.sub$AGS[shp.county.sub$AGS == "11000000"] <- "11002000"
shp.county.sub <- merge(shp.county.sub, agg, by.x="TGS", by.y="county", all.x=T)
@

\subsubsection*{Emigration rate (1984)}

<<results='asis', echo=F, warning=F, fig.width=6, fig.height=8>>=
### bin the emigration rate
shp.county.sub$emiInt1984_quartile <- NA
shp.county.sub$emiInt1984_quartile[shp.county.sub$emiInt1984 <= quantile(shp.county.sub$emiInt1984, probs=0.25, na.rm=T)] <- 1
shp.county.sub$emiInt1984_quartile[shp.county.sub$emiInt1984 > quantile(shp.county.sub$emiInt1984, probs=0.25, na.rm=T) & 
                              shp.county.sub$emiInt1984 <= quantile(shp.county.sub$emiInt1984, probs=0.5, na.rm=T)] <- 2
shp.county.sub$emiInt1984_quartile[shp.county.sub$emiInt1984 > quantile(shp.county.sub$emiInt1984, probs=0.5, na.rm=T) & 
                              shp.county.sub$emiInt1984 <= quantile(shp.county.sub$emiInt1984, probs=0.75, na.rm=T)] <- 3
shp.county.sub$emiInt1984_quartile[shp.county.sub$emiInt1984 > quantile(shp.county.sub$emiInt1984, probs=0.75, na.rm=T)] <- 4
shp.county.sub$emiInt1984_quartile <- factor(shp.county.sub$emiInt1984_quartile, levels = 1:4,
                                      labels = c("Low", "Medium-Low", "Medium-High", "High"))

### Map
map1984 <- ggplot() + 
  geom_sf(data=shp.county.sub[!is.na(shp.county.sub$emiInt1984_quartile),], aes(fill=as.factor(emiInt1984_quartile)),
          linewidth = 0.6, col="gray30") +
  geom_sf(data=shp.district.sub, fill=NA, col="black", linewidth=1.25) +    
  scale_fill_manual(values=c("seashell1", "seashell2", "seashell3", "seashell4"), 
                    name="Emigration rate (1984)")  +
  theme_bw() + 
  theme(axis.title=element_blank(), 
        axis.text=element_blank(), 
        axis.ticks=element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(size=20, face="bold", hjust=.5),
        panel.background = element_rect(fill = NA, colour = NA),
        legend.position="bottom",
        legend.title = element_text(size=14, face="bold"),
        legend.text = element_text(size=12)) +
  guides(fill = guide_legend(title.position="top", title.hjust = 0.5))  

## save
map1984
ggsave("MapEmi1984binned.png", map1984, width=6, height=8)
@

\clearpage

\subsubsection*{Ordinary crimes}

<<results='asis', echo=F, fig.width=6, fig.height=8, warning=F>>=
### Top-coding at 95th percentile
shp.county.sub$persons_total_ordinary_pc <- shp.county.sub$persons_total_ordinary / shp.county.sub$pop_total * 1000
shp.county.sub$persons_total_ordinary_pc[shp.county.sub$persons_total_ordinary_pc > quantile(shp.county.sub$persons_total_ordinary_pc, probs=0.95, na.rm=T)] <- quantile(shp.county.sub$persons_total_ordinary_pc, probs=0.95, na.rm=T)


### map
map1984 <- ggplot() +
  geom_sf(data=shp.county.sub[!is.na(shp.county.sub$persons_total_ordinary_pc),], aes(fill=persons_total_ordinary_pc),
          linewidth = 0.6, col="gray30") +
  geom_sf(data=shp.district.sub, fill=NA, col="black", linewidth=1.25) +    
  scale_fill_continuous(low="white", high="goldenrod4", 
                    name="Ordinary crimes per 1,000 capita\n(avg. 1976-1989)") +
  theme_bw() + 
  theme(axis.title=element_blank(), 
        axis.text=element_blank(), 
        axis.ticks=element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(size=20, face="bold", hjust=.5),
        panel.background = element_rect(fill = NA, colour = NA),
        legend.position="bottom",
        legend.title = element_text(size=14, face="bold"),
        legend.text = element_text(size=12)) 

## save
map1984
ggsave("MapCrimeOrdinary.png", map1984, width=6, height=8)
@

\clearpage

\subsubsection*{Anti-regime crimes}

<<results='asis', echo=F, fig.width=6, fig.height=8, warning=F>>=
### Top-coding at 95th percentile
shp.county.sub$persons_total_antiregime_pc <- shp.county.sub$persons_total_antiregime / shp.county.sub$pop_total * 1000
shp.county.sub$persons_total_antiregime_pc[shp.county.sub$persons_total_antiregime_pc > quantile(shp.county.sub$persons_total_antiregime_pc, probs=0.95, na.rm=T)] <- quantile(shp.county.sub$persons_total_antiregime_pc, probs=0.95, na.rm=T)


### map
map1984 <- ggplot() + 
  geom_sf(data=shp.county.sub[!is.na(shp.county.sub$persons_total_antiregime_pc),], aes(fill=persons_total_antiregime_pc),
          linewidth = 0.6, col="gray30") +
  geom_sf(data=shp.district.sub, fill=NA, col="black", linewidth=1.25) +    
  scale_fill_continuous(low="white", high="goldenrod4", 
                    name="Political crimes per 1,000 capita\n(avg. 1976-1989)") +
  theme_bw() + 
  theme(axis.title=element_blank(), 
        axis.text=element_blank(), 
        axis.ticks=element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(size=20, face="bold", hjust=.5),
        panel.background = element_rect(fill = NA, colour = NA),
        legend.position="bottom",
        legend.title = element_text(size=14, face="bold"),
        legend.text = element_text(size=12)) 

## save
map1984
ggsave("MapCrimeAntiRegime.png", map1984, width=6, height=8)
@

\clearpage

\subsubsection*{Border-related crimes}

<<results='asis', echo=F, fig.width=6, fig.height=8, warning=F>>=
### Top-coding at 95th percentile
shp.county.sub$persons_total_border_pc <- shp.county.sub$persons_total_border / shp.county.sub$pop_total * 1000
shp.county.sub$persons_total_border_pc[shp.county.sub$persons_total_border_pc > quantile(shp.county.sub$persons_total_border_pc, probs=0.95, na.rm=T)] <- quantile(shp.county.sub$persons_total_border_pc, probs=0.95, na.rm=T)


### map
map1984 <- ggplot() + 
  geom_sf(data=shp.county.sub[!is.na(shp.county.sub$persons_total_border_pc),], aes(fill=persons_total_border_pc),
          linewidth = 0.6, col="gray30") +
  geom_sf(data=shp.district.sub, fill=NA, col="black", linewidth=1.25) +    
  scale_fill_continuous(low="white", high="goldenrod4", 
                    name="Border-related crimes per 1,000 capita\n(avg. 1976-1989)") +
  theme_bw() + 
  theme(axis.title=element_blank(), 
        axis.text=element_blank(), 
        axis.ticks=element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(size=20, face="bold", hjust=.5),
        panel.background = element_rect(fill = NA, colour = NA),
        legend.position="bottom",
        legend.title = element_text(size=14, face="bold"),
        legend.text = element_text(size=12)) 

## save
map1984
ggsave("MapCrimeBorder.png", map1984, width=6, height=8)
@

\clearpage

\subsection*{Figure A2: International migration flows to and from the former GDR}

<<results='asis', echo=F, fig.width=12, fig.height=4, warning=F>>=
### plots
# net migration
migdata$title <- "Net migration"
p1 <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  geom_hline(yintercept=0, lty=2) +
  geom_point(data=migdata[!is.na(migdata$emi) & migdata$year<=1988,], aes(x=year, y=net),size=2.5) +  
  geom_line(data=migdata[!is.na(migdata$emi) & migdata$year<=1988,], aes(x=year, y=net),size=1) +
  xlab("Year") + 
  ylab("Net migration\n") + 
  facet_wrap(~title) +
  scale_x_continuous(breaks=seq(1964,1988,4)) +
  scale_y_continuous(limits=c(-50000,10000), breaks=seq(-50000,10000,10000),
                     labels=c("-50,000","-40,000", "-30,000", "-20,000", "-10,000","0","10,000")) +
  theme_bw() + 
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_blank(),
        axis.text = element_text(size=12))

# emigration
migdata$title <- "Emigration"
p2 <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  geom_point(data=migdata[!is.na(migdata$emi) & migdata$year<=1988,], aes(x=year, y=emi),size=2.5) +  
  geom_line(data=migdata[!is.na(migdata$emi) & migdata$year<=1988,], aes(x=year, y=emi),size=1) +
  xlab("Year") + 
  ylab("Emigration\n") + 
  facet_wrap(~title) +  
  scale_x_continuous(breaks=seq(1964,1988,4)) +
  scale_y_continuous(limits=c(0,80000), breaks=seq(0,80000,20000),
                     labels=c("0","20,000", "40,000", "60,000", "80,000")) +
  theme_bw() + 
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_blank(),
        axis.text = element_text(size=12))

# immigration
migdata$title <- "Immigration"
p3 <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  geom_point(data=migdata[!is.na(migdata$immi) & migdata$year<=1988,], aes(x=year, y=immi),size=2.5) +  
  geom_line(data=migdata[!is.na(migdata$immi) & migdata$year<=1988,], aes(x=year, y=immi),size=1) +
  xlab("Year") + 
  ylab("Immigration\n") + 
  facet_wrap(~title) +  
  scale_x_continuous(breaks=seq(1964,1988,4)) +
  scale_y_continuous(limits=c(0,80000), breaks=seq(0,80000,20000),
                     labels=c("0","20,000", "40,000", "60,000", "80,000")) +
  theme_bw() + 
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_blank(),
        axis.text = element_text(size=12))


# combine all three plots (appendix)
p <- ggarrange(p1,p2,p3, nrow=1)
p
ggsave("Migration6588combined.png", p, width=12,height=4)
@

\clearpage

\subsection*{Figure A3: Emigration from the former GDR}

\subsubsection*{Destination countries}

<<results='asis', echo=F, fig.width=7, fig.height=5, warning=F>>=
### plot
p <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  geom_point(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_BRD_share*100,
            shape="West Germany & West Berlin"), size=2.5) +
  geom_point(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Poland_share*100,
            shape="Poland"), size=2.5) +
  geom_point(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Yugoslavia_share*100,
            shape="Yugoslavia"), size=2.5) +
  geom_point(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Hungary_share*100,
            shape="Hungary"), size=2.5) +
  geom_line(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_BRD_share*100,
            lty="West Germany & West Berlin"), size=1) +
  geom_line(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Poland_share*100,
            lty="Poland"), size=1) +
  geom_line(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Yugoslavia_share*100,
            lty="Yugoslavia"), size=1) +
  geom_line(data=destcountries[destcountries$year<1989,], aes(x=year, y=emi_total_Hungary_share*100,
            lty="Hungary"), size=1) +
  scale_x_continuous(limits=c(1973,1988.5), breaks=seq(1972,1988,2)) +
  scale_y_continuous(limits=c(0,60), breaks=seq(0,60,10)) +
  scale_linetype_manual(values = c("West Germany & West Berlin" = 1,
                                "Poland" = 2,
                                "Yugoslavia" = 3,
                                "Hungary" = 4),
                     name = "Destination") +
  scale_shape_manual(values = c("West Germany & West Berlin" = 19,
                                "Poland" = 17,
                                "Yugoslavia" = 3,
                                "Hungary" = 8),
                     name = "Destination") +  
  xlab("Year") + 
  ylab("Share of Emigrants (%)") +
  theme_bw() + 
  theme(axis.title = element_text(size=14, face="bold"),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_text(size=12, face="bold"),
        legend.text = element_text(size=10))
p
ggsave("EmiCountry.png", p, width=7,height=5)
@

\clearpage

\subsubsection*{Select demographic characteristics}

<<results='asis', echo=F, fig.width=7, fig.height=5, warning=F>>=
### multiply age with number of emigrants
demo$emi_total_ageweighted <- demo$age * demo$emi_total
demo$emi_male_ageweighted <- demo$age * demo$emi_male
demo$emi_female_ageweighted <- demo$age * demo$emi_female

### aggregate
aggDEMO <- aggregate(demo[,c("emi_total", "emi_male", "emi_female", 
                        "emi_total_ageweighted", "emi_male_ageweighted", 
                        "emi_female_ageweighted")], by=list(year = demo$year), FUN=sum, na.rm=T)
aggDEMO$emi_total_ageweighted_final <- aggDEMO$emi_total_ageweighted / aggDEMO$emi_total
aggDEMO$emi_male_ageweighted_final <- aggDEMO$emi_male_ageweighted / aggDEMO$emi_male
aggDEMO$emi_female_ageweighted_final <- aggDEMO$emi_female_ageweighted / aggDEMO$emi_female
aggDEMO$female_pct <- aggDEMO$emi_female / aggDEMO$emi_total


### aggregate data
agg1 <- aggregate(demo$emi_male, by=list(year = demo$year), FUN=sum, na.rm=T)
agg2 <- aggregate(demo$emi_male_single, by=list(year = demo$year), FUN=sum, na.rm=T)
agg3 <- aggregate(demo$emi_male_single[demo$age<=25], by=list(year = demo$year[demo$age<=25]), FUN=sum, na.rm=T)
agg4 <- aggregate(demo$emi_male_single[demo$age<=30], by=list(year = demo$year[demo$age<=30]), FUN=sum, na.rm=T)
agg5 <- aggregate(demo$emi_male_single[demo$age<=35], by=list(year = demo$year[demo$age<=35]), FUN=sum, na.rm=T)

agg <- merge(agg1,agg2,by="year")
agg <- merge(agg,agg3,by="year")
agg <- merge(agg,agg4,by="year")
agg <- merge(agg,agg5,by="year")
agg <- cbind(agg, demo$emi_totalTOTAL[demo$age==0])

colnames(agg) <- c("year", "emi_male", "emi_male_single", "emi_male_single25", "emi_male_single30", 
                   "emi_male_single35", "emi_total")

agg$emi_male_share <- agg$emi_male / agg$emi_total
agg$emi_male_single_share <- agg$emi_male_single / agg$emi_total
agg$emi_male_single25_share <- agg$emi_male_single25 / agg$emi_total
agg$emi_male_single30_share <- agg$emi_male_single30 / agg$emi_total
agg$emi_male_single35_share <- agg$emi_male_single35 / agg$emi_total


### Plot: Average age and share young single men into the same plot
p <- ggplot(data=agg[agg$year<1989,]) +
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=15, ymax=45, fill="seashell3", alpha=.75) +   
  geom_point(aes(x=year, y=emi_male_single25_share*150),size=2.5) +
  geom_line(aes(x=year, y=emi_male_single25_share*150, 
                lty="Young single men (right axis)"), size=1) +
  geom_point(data=aggDEMO[aggDEMO$year<1989,], aes(x=year, y=emi_total_ageweighted_final),size=2.5)  +
  geom_line(data=aggDEMO[aggDEMO$year<1989,], aes(x=year, y=emi_total_ageweighted_final, 
                                                lty="Average age of emigrants (left axis)"), size=1) +
  scale_x_continuous(limits=c(1973,1988.5), breaks=seq(1972,1988,2)) +
  scale_y_continuous(limits=c(15,45), breaks=seq(15,45,5),
                     sec.axis = sec_axis(trans=~.*2/3, name="Share of emigrants")) +
  scale_linetype_manual(values = c("Young single men (right axis)" = 2,
                                "Average age of emigrants (left axis)" = 1), name="") +
  xlab("Year") + 
  ylab("Average age") + 
  theme_bw() + 
  theme(axis.title = element_text(size=14, face="bold"),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank(),
        legend.text = element_text(size=10))
p
ggsave("AgeMaleMigrants.png", p, width=7,height=5)
@

\clearpage

\subsection*{Table A6: Change in crime incidence after the emigration wave --- adding control variables}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 +
             SEDshare1946*post85 + university*post85 + citycounty*post85 + tv1*post85 + bordercounty*post85 + 
             infmort_3yrs + popYoung_share1984*post85
             | county + year | 0 | county, data=d)
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 +
             SEDshare1946*post85 + university*post85 + citycounty*post85 + tv1*post85 + bordercounty*post85 + 
             infmort_3yrs + popYoung_share1984*post85
             | county + year | 0 | county, data=d)
m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 +
             SEDshare1946*post85 + university*post85 + citycounty*post85 + tv1*post85 + bordercounty*post85 + 
             infmort_3yrs + popYoung_share1984*post85
             | county + year | 0 | county, data=d)
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 +
             SEDshare1946*post85 + university*post85 + citycounty*post85 + tv1*post85 + bordercounty*post85 + 
             infmort_3yrs + popYoung_share1984*post85
             | county + year | 0 | county, data=d)
m5 <- felm(persons_total_border ~ emiInt1984_dich*post85 +
             SEDshare1946*post85 + university*post85 + citycounty*post85 + tv1*post85 + bordercounty*post85 + 
             infmort_3yrs + popYoung_share1984*post85
             | county + year | 0 | county, data=d)

### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "SED share (1946)",
                             "University",
                             "Urban county",
                             "WGTV access",
                             "Border county",
                             "Infant mortality",
                             "Share young population (1984)",
                             "High emigration (1984) X Post-1984",
                             "SED share (1946) X Post-1984",
                             "University X Post-1984",
                             "Urban county X Post-1984",
                             "WGTV access X Post-1984",
                             "Border county X Post-1984",
                             "Share young population (1984) X Post-1984"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A7: Change in crime incidence after the emigration wave --- log 1984 emigration as treatment}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ log(emiInt1984) * post85 | county + year | 0 | county, data=d)
m2 <- felm(persons_total_ordinary ~ log(emiInt1984) * post85 | county + year | 0 | county, data=d)
m3 <- felm(persons_total_antiregime ~ log(emiInt1984) * post85 | county + year | 0 | county, data=d)
m4 <- felm(persons_total_antiregimeNoBorder ~ log(emiInt1984) * post85 | county + year | 0 | county, data=d)
m5 <- felm(persons_total_border ~ log(emiInt1984) * post85 | county + year | 0 | county, data=d)


### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("Emigration rate (log, 1984)",
                             "Post-1984",
                             "Emigration rate (log, 1984) X Post-1984"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A8: Short- vs. long-term consequences --- log 1984 emigration as treatment}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_ordinary ~ log(emiInt1984) * as.factor(yearPOST) | county + year | 0 | county, data=d)
m2 <- felm(persons_total_antiregimeNoBorder ~ log(emiInt1984) * as.factor(yearPOST) | county + year | 0 | county, data=d)
m3 <- felm(persons_total_border ~ log(emiInt1984) * as.factor(yearPOST) | county + year | 0 | county, data=d)


### stargazer output
stargazer(m1,m2,m3,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T, 
          dep.var.labels = c("ordinary","political excl. border", "border"),
          covariate.labels=c("Log emigration (1984)",
                             "t+1 (1985)",
                             "t+3 (1987)",
                             "t+4 (1988)",
                             "t+5 (1989)",
                             "Log emigration (1984) X t+1 (1985)",
                             "Log emigration (1984) X t+3 (1987)",
                             "Log emigration (1984) X t+4 (1988)",
                             "Log emigration (1984) X t+5 (1989)"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A9: Change in crime incidence after the emigration wave --- increase in emigration as treatment}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt_diff_dich * post85 | county + year | 0 | county, data=d)
m2 <- felm(persons_total_ordinary ~ emiInt_diff_dich * post85 | county + year | 0 | county, data=d)
m3 <- felm(persons_total_antiregime ~ emiInt_diff_dich * post85 | county + year | 0 | county, data=d)
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt_diff_dich * post85 | county + year | 0 | county, data=d)
m5 <- felm(persons_total_border ~ emiInt_diff_dich * post85 | county + year | 0 | county, data=d)


### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("Above-median increase in emigration (1984 vs. 1979)",
                             "Post-1984",
                             "Above-median increase in emigration (1984 vs. 1979) X Post-1984"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A10: Change in crime incidence after the emigration wave --- Count of unique crimes as dependent variable}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(crimeCount_all ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m2 <- felm(crimeCount_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m3 <- felm(crimeCount_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m4 <- felm(crimeCount_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m5 <- felm(crimeCount_border ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)


### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A11: Change in crime incidence after the emigration wave --- Dependent variable scaled by population}


<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(I(persons_total_all/pop_total*1000) ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m2 <- felm(I(persons_total_ordinary/pop_total*1000) ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m3 <- felm(I(persons_total_antiregime/pop_total*1000) ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m4 <- felm(I(persons_total_antiregimeNoBorder/pop_total*1000) ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)
m5 <- felm(I(persons_total_border/pop_total*1000) ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d)


### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          #column.labels = rep(c("constant", "current"),5),
          dep.var.labels.include = T,
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("County-FE?", rep("YES", 5)),
            c("Year-FE?", rep("YES", 5))), 
          digits = 3)
@

\clearpage

\subsection*{Table A12: Robustness to changes in the sample composition 1: drop outliers on DV}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 | county + year | 0 | county, 
           data=d, subset=d$crimeCount_all < quantile(d$crimeCount_all, probs=0.95,na.rm=T))
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, 
           data=d, subset=d$crimeCount_all < quantile(d$crimeCount_all, probs=0.95,na.rm=T))
m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, 
           data=d, subset=d$crimeCount_all < quantile(d$crimeCount_all, probs=0.95,na.rm=T))
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, 
           data=d, subset=d$crimeCount_all < quantile(d$crimeCount_all, probs=0.95,na.rm=T))
m5 <- felm(persons_total_border ~ emiInt1984_dich * post85 | county + year | 0 | county, 
           data=d, subset=d$crimeCount_all < quantile(d$crimeCount_all, probs=0.95,na.rm=T))

### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("Sample?", "95 percent", "95 percent", "95 percent", "95 percent", "95 percent"),
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A13: Robustness to changes in the sample composition 2: non-urban counties}

\textit{Note:} Dropping all counties that have comprise exactly one municipality.

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$citycounty == 0)
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$citycounty == 0)
m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$citycounty == 0)
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$citycounty == 0)
m5 <- felm(persons_total_border ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$citycounty == 0)

### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("Sample?", "Non-urban", "Non-urban", "Non-urban", "Non-urban", "Non-urban"),
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Table A14: Robustness to changes in the sample composition 3: drop counties with universities}

<<results='asis', echo=F, warning=F>>=
### Regressions
m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$university == 0)
m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$university == 0)
m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$university == 0)
m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$university == 0)
m5 <- felm(persons_total_border ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$university == 0)

### stargazer output
stargazer(m1,m2,m3,m4,m5,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("all", "ordinary", "political", "political excl. border", "border"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "High emigration (1984) X Post-1984"), 
          add.lines = list(
            c("Sample?", "No college", "No college", "No college", "No college", "No college"),
            c("County-FE?", "YES", "YES", "YES", "YES", "YES"),
            c("Year-FE?", "YES", "YES", "YES", "YES", "YES")), 
          digits = 3)
@

\clearpage

\subsection*{Figure A4: Robustness to omitting one district at a time}

<<results='asis', echo=F, warning=F>>=
### code districts
d$districtID <- as.numeric(substr(d$countyID, 1,2))

### create output container
out <- data.frame(matrix(nrow=75, ncol=4))
colnames(out) <- c("district", "outcome", "b", "se")
out$district <- rep(1:15,each=5)
out$outcome <- rep(1:5,15)
out$outcome <- factor(out$outcome, levels=1:5,
                      labels = c("all crimes",
                                 "ordinary crimes",
                                 "political crimes",
                                 "political crimes (excl. border)",
                                 "border-related crimes"))

### loop through all districts
for(i in 1:15){
  # regressions
  m1 <- felm(persons_total_all ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$districtID != i)
  m2 <- felm(persons_total_ordinary ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$districtID != i)
  m3 <- felm(persons_total_antiregime ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$districtID != i)
  m4 <- felm(persons_total_antiregimeNoBorder ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$districtID != i)
  m5 <- felm(persons_total_border ~ emiInt1984_dich * post85 | county + year | 0 | county, data=d, subset=d$districtID != i)
  
  # get coefficient of interest
  out[out$district == i,c("b", "se")] <- rbind(summary(m1)$coef[3,1:2], summary(m2)$coef[3,1:2], 
                                               summary(m3)$coef[3,1:2], summary(m4)$coef[3,1:2], 
                                               summary(m5)$coef[3,1:2])
}

### factorize the district
out$district <- factor(out$district, levels=1:15,
                       labels = c("Rostock", "Schwerin", "Neubrandenburg",
                                  "Potsdam", "Frankfurt", "Cottbus",
                                  "Magdeburg", "Halle", 
                                  "Erfurt", "Gera", "Suhl",
                                  "Dresden", "Leipzig", "Karl-Marx-Stadt",
                                  "Berlin"))


### Plot
p <- ggplot() + 
  geom_hline(yintercept = 0, lty=2) +
  geom_point(data=out, aes(x=district, y=b)) +
  geom_errorbar(data=out, aes(x=district, ymin=b-1.96*se, ymax=b+1.96*se), width=0) +
  facet_wrap(~outcome) +
  xlab("Omitted district") +
  ylab("Difference-in-differences\nestimate") +
  theme_bw() +
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_text(size=14, face="bold"),
        axis.text.x = element_text(size=12, angle=90, hjust=1, vjust=0.5),
        axis.text.y = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank(),
        legend.text = element_text(size=12))
p
ggsave("LOO_Crime.png", p, width=10, height=6)
@

\clearpage

\subsection*{Figure A5: Emigration increases subsequent demand for emigration: event study plot}

<<results='asis', echo=F, warning=F, fig.width=7, fig.height=4>>=
### regression
m <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt1984_dich*as.factor(yearEVENT85_demand) +
             SEDshare1946*as.factor(yearEVENT85_demand) + university*as.factor(yearEVENT85_demand) + 
            citycounty*as.factor(yearEVENT85_demand) + 
            tv1*as.factor(yearEVENT85_demand) + bordercounty*as.factor(yearEVENT85_demand) + 
              popYoung_share1984*as.factor(post84) + infmort_3yrs            
           |countyID + year |0|countyID, subset=d$year >= 1978,
           data=d)


### extract data for plot
out <- data.frame(matrix(nrow=12, ncol=3))
colnames(out) <- c("year", "b", "se")
out$year <- 1978:1989
out[1,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1978", 1:2]
out[2,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1979", 1:2]
out[3,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1980", 1:2]
out[6,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1983", 1:2]
out[7,2:3] <- c(0,NA)
out[9,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1986", 1:2]
out[10,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1987", 1:2]
out[11,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1988", 1:2]
out[12,2:3] <- summary(m)$coef["emiInt1984_dich:as.factor(yearEVENT85_demand)1989", 1:2]

### plot
p <- ggplot() + 
  annotate("rect", xmin=1984.5, xmax=1989.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +  
  geom_hline(yintercept = 0, lty=2) +
  geom_point(data=out, aes(x=year, y=b)) +
  geom_errorbar(data=out, aes(x=year, ymin=b-1.96*se, ymax=b+1.96*se), width=0) +
  scale_x_continuous(breaks=1977:1989) +
  xlab("") +
  ylab("Estimated change in demand for exit\nHigh- vs. low-emigration counties") +
  theme_bw() + 
  theme(strip.text = element_text(size=14, face="bold", hjust=.5),
        axis.title = element_text(size=14, face="bold"),
        axis.text = element_text(size=12),
        legend.position = "bottom",
        legend.title = element_blank(),
        legend.text = element_text(size=12))
p
ggsave("DiffInDiff_DemandExit.png", p, width=7, height=4)
@

\clearpage

\subsection*{Table A15: Increase in demand for future emigration following the emigration wave}

<<results='asis', echo=F, warning=F>>=
### Regressions
# Exit visa petitions
m1 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt1984_dich*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m2 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt1984_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + citycounty*as.factor(post84) + 
             tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m3 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt1984_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + citycounty*as.factor(post84) + 
             tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)

# Domestic affairs and travel
m4 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt1984_dich*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m5 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt1984_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + citycounty*as.factor(post84) + 
             tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m6 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt1984_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + citycounty*as.factor(post84) + 
             tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)


### Output
stargazer(m1,m2,m3,m4,m5,m6,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("Exit visas", "Domestic affairs (incl. travel)"),
          covariate.labels=c("High emigration (1984)",
                             "Post-1984",
                             "Share SED (1946)",
                             "University",                             
                             "Urban county",
                             "WGTV access",
                             "Border county",
                             "Share young population (1984)",
                             "Infant mortality rate",
                             "Share unskilled workers (1989)",
                             "Unemployment rate (1991)",
                             "High emigration (1984) x Post-1984",
                             "Share SED (1946) x Post-1984",
                             "University x Post-1984",
                             "Urban county x Post-1984",
                             "WGTV access x Post-1984",
                             "Border county x Post-1984",
                             "Share young population x Post-1984",
                             "Share unskilled workers (1989) x Post-1984",
                             "Unemployment rate (1991) x Post-1984"), 
          add.lines = list(
            c("County-FE?", rep("YES", 6)),
            c("Year-FE?", rep("YES", 6))), 
          digits = 3) 
@

\clearpage

\subsection*{Table A16: Increase in demand for emigration following the emigration wave: log emigration}

<<results='asis', echo=F, warning=F>>=
### Regressions
# Exit visa petitions
m1 <- felm(I(petitions_SR_exit_pc*1000) ~ log(emiInt1984)*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m2 <- felm(I(petitions_SR_exit_pc*1000) ~ log(emiInt1984)*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m3 <- felm(I(petitions_SR_exit_pc*1000) ~ log(emiInt1984)*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)            
           |countyID + year |0|countyID, 
           data=d)

# Domestic affairs and travel
m4 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ log(emiInt1984)*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m5 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ log(emiInt1984)*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m6 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ log(emiInt1984)*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)  
           |countyID + year |0|countyID, 
           data=d)


### Output
stargazer(m1,m2,m3,m4,m5,m6,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("Exit visas", "Domestic affairs (incl. travel)"),
          covariate.labels=c("Emigration rate (log, 1984)",
                             "Post-1984",
                             "Share SED (1946)",
                             "University",                             
                             "Urban county",
                             "WGTV access",
                             "Border county",
                             "Share young population (1984)",
                             "Infant mortality rate",                             
                             "Share unskilled workers (1989)",
                             "Unemployment rate (1991)",
                             "Emigration rate (log, 1984) x Post-1984",
                             "Share SED (1946) x Post-1984",
                             "University x Post-1984",
                             "Urban county x Post-1984",
                             "WGTV access x Post-1984",
                             "Border county x Post-1984",
                             "Share young population (1984) x Post-1984",
                             "Share unskilled workers (1989) x Post-1984",
                             "Unemployment rate (1991) x Post-1984"), 
          add.lines = list(
            c("County-FE?", rep("YES", 6)),
            c("Year-FE?", rep("YES", 6))), 
          digits = 3) 
@

\clearpage

\subsection*{Table A17: Increase in demand for future emigration following the emigration wave: increase in emigration}

<<results='asis', echo=F, warning=F>>=
### Regressions
# Exit visa petitions
m1 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt_diff_dich*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m2 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt_diff_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m3 <- felm(I(petitions_SR_exit_pc*1000) ~ emiInt_diff_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)  
           |countyID + year |0|countyID, 
           data=d)

# Domestic affairs and travel
m4 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt_diff_dich*as.factor(post84)
           |countyID + year |0|countyID, 
           data=d)
m5 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt_diff_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs
           |countyID + year |0|countyID, 
           data=d)
m6 <- felm(I(petitions_SR_domesticTravel_pc*1000) ~ emiInt_diff_dich*as.factor(post84) + 
             SEDshare1946*as.factor(post84) + university*as.factor(post84) + 
             citycounty*as.factor(post84) + tv1*as.factor(post84) + bordercounty*as.factor(post84) + 
             popYoung_share1984*as.factor(post84) + infmort_3yrs +
             workers_lowskill_pc1989*as.factor(post84) + unemprate1991*as.factor(post84)  
           |countyID + year |0|countyID, 
           data=d)


### Output
stargazer(m1,m2,m3,m4,m5,m6,
          omit.stat = c("rsq", "f", "ser"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,          
          dep.var.labels  = c("Exit visas", "Domestic affairs (incl. travel)"),
          covariate.labels=c("Above-median increase in emigration (1984 vs. 1979)",
                             "Post-1984",
                             "Share SED (1946)",
                             "University",                             
                             "Urban county",
                             "WGTV access",
                             "Border county",
                             "Share young population (1984)",
                             "Infant mortality rate",                             
                             "Share unskilled workers (1989)",
                             "Unemployment rate (1991)",
                             "Above-median increase in emigration (1984 vs. 1979) x Post-1984",
                             "Share SED (1946) x Post-1984",
                             "University x Post-1984",
                             "Urban county x Post-1984",
                             "WGTV access x Post-1984",
                             "Border county x Post-1984",
                             "Share young population (1984) x Post-1984",
                             "Share unskilled workers (1989) x Post-1984",
                             "Unemployment rate (1991) x Post-1984"), 
          add.lines = list(
            c("County-FE?", rep("YES", 6)),
            c("Year-FE?", rep("YES", 6))), 
          digits = 3) 
@

\clearpage

\subsection*{Figure A6: No difference in government expenditure after the emigration wave}

<<results='asis', echo=F, fig.width=9, fig.height=6, warning=F>>=
### create data to be plotted
toplot1 <- subset(govexp, select = c(year, expenditures_total_pc))
colnames(toplot1) <- c("year", "value")
toplot1$outcome <- "Expenditures per capita\n(GDR Marks)"
toplot1$type <- "All government expenditures"

toplot2 <- subset(govexp, select = c(year, expenditures_social_pc))
colnames(toplot2) <- c("year", "value")
toplot2$outcome <- "Expenditures per capita\n(GDR Marks)"
toplot2$type <- "Social programs"

toplot3 <- subset(govexp, select = c(year, expenditures_total_pc_growth))
colnames(toplot3) <- c("year", "value")
toplot3$outcome <- "Growth in expenditures\n(% of previous year)"
toplot3$type <- "All government expenditures"

toplot4 <- subset(govexp, select = c(year, expenditures_social_pc_growth))
colnames(toplot4) <- c("year", "value")
toplot4$outcome <- "Growth in expenditures\n(% of previous year)"
toplot4$type <- "Social programs"

toplot <- rbind(toplot1, toplot2, toplot3, toplot4)


### plot
toplot$value[toplot$outcome == "Growth in expenditures\n(% of previous year)"] <- toplot$value[toplot$outcome == "Growth in expenditures\n(% of previous year)"] * 100

p <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  geom_line(data=toplot, aes(x=year, y=value), size=1) +
  scale_x_continuous(limits=c(1960,1990),
                     breaks=seq(1960,1990,5)) +
  facet_grid(outcome~type, scales="free") +
  theme_bw() + 
  theme(axis.title = element_blank(),
        axis.text = element_text(size=12),
        strip.text = element_text(size=14, face="bold"))
p
ggsave("GovExpenditures.png", p, width=9, height=6)
@

\clearpage

\subsection*{Figure A7: Number of reported successful illegal border crossings by year}

<<results='asis', echo=F, fig.width=7, fig.height=4, warning=F>>=
### plot
p <- ggplot() + 
  annotate("rect", xmin=1983.5, xmax=1988.5, ymin=-Inf, ymax=Inf, fill="seashell3", alpha=.75) +    
  annotate("text", x=1975,y=1100, label = "East German\nestimates", size=4) +
  annotate("text", x=1969,y=8000, label = "West German\nestimates", size=4) +
  geom_line(data=exits, aes(x=year, y=exits_gdr, col="East German estimates"), size=1) +
  geom_line(data=exits, aes(x=year, y=exits_frg, col="West German estimates"), size=1) +
  scale_x_continuous(limits=c(1960,1990),
                     breaks=seq(1960,1990,5)) +  
  scale_y_continuous(limits=c(0,17000),
                     breaks=seq(0,16000,4000),
                     labels = c("0", "4,000", "8,000", "12,000", "16,000")) +
  scale_color_manual(values =c("gray20", "gray60"), name="") +
  ylab("Estimated number of\nsuccessful refugees") +
  theme_bw() + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size=12, face="bold"),
        axis.text = element_text(size=12),
        strip.text = element_text(size=14, face="bold"),
        legend.position = "none")  
p
ggsave("SuccessfulExits.png", p, width=7, height=4)
@





\end{document}


